<html>
<head>
    <title>YUI Test Example</title>
    <link type="text/css" rel="stylesheet" href="../build/logger/assets/logger.css" />     
    <link type="text/css" rel="stylesheet" href="../build/yuitest/assets/testlogger.css" />
    <script type="text/javascript" src="../build/yahoo/yahoo.js"></script>
    <script type="text/javascript" src="../build/dom/dom.js"></script>
    <script type="text/javascript" src="../build/event/event.js"></script>
    <script type="text/javascript" src="../build/logger/logger.js"></script>
    <script type="text/javascript" src="../build/yuitest/yuitest-beta.js"></script>
</head>
<body>
    <h1>YUI Test Example</h1>
    <h2>Advanced Test Options</h2>
    <p>This example shows how to configure advanced test options. These may be necessary
    when your tests are more complicated than having simple assertions. With advanced
    test options, you can specify:</p> 
    <ul>
        <li>that a given test is supposed to fail (in which case it
        passes becauses the failure was expected)</li>
        <li>that a given test should throw an error (in which case it passes because
        the error was expected)</li>
        <li>that a given test should be ignored and not run</li>
    </ul>
    <p>View the source of this page to see how it works.</p>
    <p><input type="button" value="Run Tests" id="btnRun" /></p>
    
    <script type="text/javascript">
    
        var testCase = new YAHOO.tool.TestCase({
        
            //the name of the test case - if not provided, one is automatically generated
            name: "Advanced Options Tests",
            
            /*
             * Specifies tests that "should" be doing something other than the expected.
             */
            _should: {
            
                /*
                 * Tests listed in here should fail, meaning that if they fail, the test
                 * has passed. This is used mostly for YuiTest to test itself, but may
                 * be helpful in other cases.
                 */
                fail: {
                
                    //the test named "testFail" should fail
                    testFail: true
                
                },
                
                /*
                 * Tests listed here should throw an error of some sort. If they throw an
                 * error, then they are considered to have passed.
                 */
                error: {
                
                    /*
                     * You can specify "true" for each test, in which case any error will
                     * cause the test to pass.
                     */
                    testGenericError: true,
                    
                    /*
                     * You can specify an error message, in which case the test passes only
                     * if the error thrown matches the given message.
                     */
                    testStringError: "I'm a specific error message.",
                    testStringError2: "I'm a specific error message.",
                    
                    /*
                     * You can also specify an error object, in which case the test passes only
                     * if the error thrown is on the same type and has the same message.
                     */
                    testObjectError: new TypeError("Number expected."),            
                    testObjectError2: new TypeError("Number expected."),
                    testObjectError3: new TypeError("Number expected.")
                
                },
                
                /*
                 * Tests listed here should be ignored when the test case is run. For these tests,
                 * setUp() and tearDown() are not called.
                 */
                ignore : {
                
                    testIgnore: true
                    
                }    
            },
            
            //-------------------------------------------------------------------------
            // Basic tests - all method names must begin with "test"
            //-------------------------------------------------------------------------
            
            testFail : function() {
            
                //force a failure - but since this test "should" fail, it will pass
                YAHOO.util.Assert.fail("Something bad happened.");
                
            },
            
            testGenericError : function() {    
                throw new Error("Generic error");        
            },
            
            testStringError : function() {
                
                //throw a specific error message - this will pass because it "should" happen
                throw new Error("I'm a specific error message.");    
            },
            
            testStringError2 : function() {
                
                //throw a specific error message - this will fail because the message isn't expected
                throw new Error("I'm a specific error message, but a wrong one.");    
            },
            
            testObjectError : function() {
                
                //throw a specific error and message - this will pass because it "should" happen
                throw new TypeError("Number expected.");    
            },
            
            testObjectError2 : function() {
                
                //throw a specific error and message - this will fail because the type doesn't match
                throw new Error("Number expected."); 
            },
            
            testObjectError3 : function() {
                
                //throw a specific error and message - this will fail because the message doesn't match
                throw new TypeError("String expected.");    
            },
            
            testIgnore : function () {
                alert("You'll never see this.");
            }
            
        });    
        
        function runTests(){
            YAHOO.tool.TestRunner.run();
        }
    
        // YAHOO.util.Event.onDomReady(function (){ // need to wait for the frame to load
        YAHOO.util.Event.on(window, "load", function (){
            //create the logger
            var logger = new YAHOO.tool.TestLogger();
            
            //add the tests
            YAHOO.tool.TestRunner.add(testCase);
            
            //add event handler
            YAHOO.util.Event.addListener("btnRun", "click", runTests);
    
            runTests();
        });        
    
    </script>
        


</body>
</html>
